package com.example.designpatterns.command.concrete;

import com.example.designpatterns.command.Command;
import com.example.designpatterns.command.receiver.Light;

/**
 * DimLightCommand类 - 调整灯光亮度命令
 */
public class DimLightCommand implements Command {
    private Light light;
    private int brightness;
    private int previousBrightness;
    
    /**
     * 创建调光命令
     * @param light 灯光对象
     * @param brightness 要设置的亮度
     */
    public DimLightCommand(Light light, int brightness) {
        this.light = light;
        this.brightness = brightness;
    }
    
    @Override
    public void execute() {
        // 保存当前亮度以便撤销
        previousBrightness = light.getBrightness();
        light.setBrightness(brightness);
    }
    
    @Override
    public boolean undo() {
        light.setBrightness(previousBrightness);
        return true;
    }
    
    @Override
    public String getName() {
        return "将" + light.getLocation() + "的灯光亮度调整到" + brightness;
    }
} 